<%--
  Created by IntelliJ IDEA.
  User: z5727
  Date: 2022/9/29
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<!doctype html>
<html lang="en" class="pxp-root">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="shortcut icon" href="/static/web/images/favicon.png" type="image/x-icon">
    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;600;700&display=swap" rel="stylesheet">
    <link href="/static/web/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/web/css/owl.carousel.min.css">
    <link rel="stylesheet" href="/static/web/css/owl.theme.default.min.css">
    <link rel="stylesheet" href="/static/web/css/animate.css">
    <link rel="stylesheet" href="/static/web/css/style.css">
    <link rel="stylesheet" href="/static/web/css/iconcss/iconfont.css">
    <title>Jobster - Company dashboard - Candidates</title>
</head>
<body style="background-color: var(--pxpMainColorLight);">
<div class="pxp-preloader"><span>Loading...</span></div>

<jsp:include page="/web/companies/inc/companyHead"/>

    <div class="pxp-dashboard-content-details">
        <h1>候选人名单</h1>
        <p class="pxp-text-light">申请工作的候选人名单</p>

        <div class="mt-4 mt-lg-5">
            <div class="row justify-content-between align-content-center">
                <div class="col-auto order-2 order-sm-1">
                    <div class="pxp-company-dashboard-jobs-bulk-actions mb-3">
                        <select class="form-select">
                            <option value="1">批量操作</option>
                            <option value="2">通过</option>
                            <option value="3">拒绝</option>
                            <option value="4">删除</option>
                        </select>
                        <button class="btn ms-2 cao_zuo" >操作</button>
                    </div>
                </div>
                <div class="col-auto order-1 order-sm-2">
                    <div class="pxp-company-dashboard-jobs-search mb-3">
                        <div class="pxp-company-dashboard-jobs-search-results me-3 candidates_count">16 名候选人</div>
                        <div class="pxp-company-dashboard-jobs-search-search-form">
                            <div class="input-group">
                                <span class="input-group-text search_all" style="cursor: pointer;color: #0a53be"><span class="fa fa-search"></span></span>
                                <input type="text" class="form-control search_keyword" placeholder="Search candidates...">
                            </div>
                            <input type="hidden" class="search_hidden">
                        </div>
                    </div>
                </div>
            </div>
            <div class="table-responsive apply_position">




            </div>
        </div>
    </div>
    <div id="flow_window">

<jsp:include page="/web/companies/inc/companyFoot"/>

</div>

<script src="/static/web/js/jquery-3.4.1.min.js"></script>
<script src="/static/web/js/bootstrap.bundle.min.js"></script>
<script src="/static/web/js/owl.carousel.min.js"></script>
<script src="/static/web/js/nav.js"></script>
<script src="/static/web/js/Chart.min.js"></script>
<script src="/static/web/js/main.js"></script>
<script type="text/javascript">
    $(function (){
        initData(1);
        //更改页码
        $(".apply_position").on("click",".page-link",function (){
            let pageNum = $(this).html();
            initData(pageNum);
            return false;
        })
        //全选或全不选
        $(".apply_position").on("click",".select_all",function (){
            let checked = $(this).prop("checked");
            alert(checked);
            $(".apply_position").find(".select_one").each(function (){
                $(this).prop("checked",checked);
            })
        });
        //批量操作面试通过
        $(".cao_zuo").click(function (){
            let conet = $(".form-select").val();
            var applyPositionIds = new Array();
            //批量通过
            if (conet=="2")
            {
                if(confirm("您确定要批量通过吗？")){
                let checked;
                let applyPositionId;
                $(".apply_position").find(".select_one").each(function (){
                    let applyStatus = $(this).data("name");
                    if(applyStatus==0||applyStatus==1){
                        checked = $(this).prop("checked");
                        applyPositionId = $(this).data("id");
                        if(checked==true)
                        {
                            applyPositionId = parseInt(applyPositionId);
                            applyPositionIds.push(applyPositionId);
                        }
                    }
                    if (applyStatus==3||applyStatus==4){
                        alert("已通过或拒绝的面试邀请无法修改");
                        return false;
                    }
                });
                applyPositionIds = applyPositionIds.join(",");
                if(applyPositionIds!=''){
                let data={applyPositionIds:applyPositionIds,applyStatus:2};
                $.get("/web/companies/companiesHomePageCandidates/updateApplyStatus",
                    data,
                    function (meg){
                        initData(1);
                    }
                )
                }
                }
            }
            //批量拒绝
            if (conet=="3")
            {
                if(confirm("您确定要批量拒绝吗?")){
                let checked;
                let applyPositionId;
                $(".apply_position").find(".select_one").each(function (){
                    let applyStatus = $(this).data("name");
                    if(applyStatus==0||applyStatus==1) {
                        checked = $(this).prop("checked");
                        applyPositionId = $(this).data("id");
                        if (checked == true) {
                            applyPositionId = parseInt(applyPositionId);
                            applyPositionIds.push(applyPositionId);
                        }
                    }
                    if (applyStatus==3||applyStatus==4){
                        alert("已通过或拒绝的面试邀请无法修改");
                        return false;
                    }
                });
                applyPositionIds = applyPositionIds.join(",");
                if (applyPositionIds!=''){
                let data={applyPositionIds:applyPositionIds,applyStatus:3};
                $.get("/web/companies/companiesHomePageCandidates/updateApplyStatus",
                    data,
                    function (meg){
                        initData(1);
                    }
                )
                }
            }
            }
            //批量删除
            if (conet=="4")
            {
                if(confirm("您确定要删除这些面试邀请通知吗？")){
                let checked;
                let applyPositionId;
                $(".apply_position").find(".select_one").each(function (){
                    checked = $(this).prop("checked");
                    applyPositionId = $(this).data("id");
                    if(checked==true)
                    {
                        applyPositionId = parseInt(applyPositionId);
                        applyPositionIds.push(applyPositionId);
                    }
                });
                applyPositionIds = applyPositionIds.join(",");
                let data={applyPositionIds:applyPositionIds};
                $.get("/web/companies/comaniesHomePageCandidates/enableApplyPosition",
                    data,
                    function (meg){
                        initData(1);
                    }
                )
            }
            }
        });
        //点击通过面试按钮修改求职者面试进度（面试成功）
        $(".apply_position").on("click",".a-check",function (){
            let applyPositionId = $(this).data("id");
            let data={applyPositionIds:applyPositionId,applyStatus:2};
            $.get("/web/companies/companiesHomePageCandidates/updateApplyStatus",
                data,
                function (meg){
                    initData(1);
                }
            )
        })
        //点击通过面试按钮修改求职者面试进度（已拒绝）
        $(".apply_position").on("click",".a-ban",function (){
            let applyPositionId = $(this).data("id");
            let data={applyPositionIds:applyPositionId,applyStatus:3};
            $.get("/web/companies/companiesHomePageCandidates/updateApplyStatus",
                data,
                function (meg){
                    initData(1);
                }
            )
        })
        //删除求职者面试进度
        $(".apply_position").on("click",".a-del",function (){
            let applyPositionId = $(this).data("id");
            let data={applyPositionIds:applyPositionId};
            $.get("/web/companies/comaniesHomePageCandidates/enableApplyPosition",
                data,
                function (meg){
                    initData(1);
                }
            )
        })
        //关键词查询
        $(".search_all").click(searchPosition);

        //查看求职者简历
        $(".apply_position").on("click",".view_position",function (){
            let userId = $(this).data("id");
            $.get("/web/companies/companiesHomePageCandidatesPositionData",
            data={userId:userId},
                function (msg){
                $("#flow_window").html(msg);
                }
        )
        })
        //关闭求职者简历弹窗
            $("#flow_window").on("click","#close",function (){
                $(this).parent().parent().css("display","none");
            })
        // 点击其他位置关闭弹窗
        window.onclick = function(event){
            if(event.target ==$("#flow_window").find("#modal")){
                $("#flow_window").find("#modal").css("display","none");
            }
        }
    })
    function searchPosition()
    {
        initData(1);
    }

    function initData(pageNum)
    {
        $(".search_hidden").val($(".search_keyword").val());
        let keyword = $(".search_hidden").val();
        let data={pageNum:pageNum,keyword:keyword};
        $.get("/web/companies/companiesHomePageCandidatesData",
            data,
            function (data){
                $(".apply_position").html(data);
                let count = $(".apply_position").find(".col-auto").data("id");
                $(".candidates_count").html(count+" 个候选人");
            })
    }
</script>
</body>
</html>
